#!/bin/sh
#

stty -echo;
#read -p "Input IP:" HOST;
stty echo;
echo;
HOST=$1
A=cdn@HPISC;
#A=$2


./scpScript $HOST $A;

echo "Connecting to $HOST"
expect -c "set timeout -1;\
spawn ssh $HOST -l root \"/usr/sbin/useradd nagios -s /bin/nologin;cd /tmp;tar -xzvf nagios-plugins-1.4.15.tar.gz; tar -xzvf nrpe-2.12.tar.gz;cd nagios-plugins-1.4.15;./configure;make;make install;cat /tmp/services_line>>/etc/services;tail -2 /etc/services;cd  ../nrpe-2.12;./configure;make all;make install-plugin;make install-daemon;make install-daemon-config;make install-xinetd;\";\

match_max 100000;\
expect *password:*;\
send -- $A\r;\

interact;"

echo "+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++"

./scpNrpe $HOST $A;

./restartxinetd $HOST $A;

/usr/local/nagios/libexec/check_nrpe -H $HOST

echo "Finished job on $HOST"
exit 0